﻿@model GolfLeague.EditModels.CourseEditModel

<script src="@Url.Content("~/Content/scripts/jquery.maskedinput-1.3.min.js")" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#dialog').dialog({
            autoOpen: false,
            model: true
        });
        $('#NewCourse_ZipCode').mask("99999?-9999");
        $('input:button').button();
        $('input:submit').button();
        $('input:reset').button();
        $('div#buttonlist a').hover(
		    function () { $(this).addClass('ui-state-hover'); },
		    function () { $(this).removeClass('ui-state-hover'); }
	    );
    });

    $(function () {
        $(".DeleteButton").click(function (e) {
            e.preventDefault();
            var recordToDelete = $(this).attr("id");
            recordToDelete = recordToDelete.replace("delete-", "");

            $("#dialog").dialog("option", "buttons", {
                "Yes": function () {
                    $(this).dialog("close");
                    if (recordToDelete != '') {
                        $.post("CourseDelete", { "courseID": recordToDelete },
                        function (data) {
                            $('#row-' + recordToDelete).fadeOut('slow');
                        });
                    }
                },
                "No": function () {
                    $(this).dialog("close");
                    return false;
                }
            });
            $("#dialog").dialog("open");
        });
    });

    $(function () {
        $(".ScorecardButton").click(function (e) {
            e.preventDefault();
            var scorecardRecord = $(this).attr("id");
            scorecardRecord = scorecardRecord.replace("scorecard-", "");

            if (scorecardRecord != '') {
                window.location = '/Course/Scorecard/' + scorecardRecord;
            }
        });
    });

    $(function () {
        $(".EditButton").click(function (e) {
            e.preventDefault();
            var recordToEdit = $(this).attr("id");
            recordToEdit = recordToEdit.replace("edit-", "");

            if (recordToEdit != '') {
                window.location = '/Course/CourseEdit/' + recordToEdit;
            }
        });
    });

    $(function () {
        $(".CancelEditButton").click(function (e) {
            e.preventDefault();
            window.location = "../";
        });
    });

</script>

@{
    ViewBag.Title = "Courses";
}
@Html.ActionLink("Admin Home", "Index") > Courses<br /><br />

@using (Html.BeginForm())
{
<fieldset>
    <legend>Add Course</legend>

    @Html.HiddenFor(model => model.NewCourse.CourseID)

    <div class="editor-label">
        @Html.LabelFor(model => model.NewCourse.CourseName)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.NewCourse.CourseName)
        @Html.ValidationMessageFor(model => model.NewCourse.CourseName)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.NewCourse.Address)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.NewCourse.Address)
        @Html.ValidationMessageFor(model => model.NewCourse.Address)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.NewCourse.City)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.NewCourse.City)
        @Html.ValidationMessageFor(model => model.NewCourse.City)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.NewCourse.State)
    </div>
    <div class="editor-field">
        @Html.DropDownListFor(model => model.NewCourse.State, new SelectList(Model.statesList))
        @Html.ValidationMessageFor(model => model.NewCourse.State)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.NewCourse.ZipCode)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.NewCourse.ZipCode)
        @Html.ValidationMessageFor(model => model.NewCourse.ZipCode)
    </div>
    <p>
        @if (Model.NewCourse.CourseID < 1)
        {
            <input type="submit" value="Add" />
        }
        else
        {
            <input type="submit" value="Save" />
            <input type="reset" class="CancelEditButton" value="Cancel" />
        }
    </p>
    <div id="dialog" title="Confirm Delete">Are you sure you want to delete this course?</div>
</fieldset>
}

<fieldset>
    <legend>Courses</legend>
    <table>
        <tr>
            <th>
                CourseName
            </th>
            <th>
                Address
            </th>
            <th>
                City
            </th>
            <th>
                State
            </th>
            <th>
                ZipCode
            </th>
            <th></th>
        </tr>

@foreach (var item in Model.Courses) {
        <tr id="row-@item.CourseID">
            <td>
                @item.CourseName
            </td>
            <td>
                @item.Address
            </td>
            <td>
                @item.City
            </td>
            <td>
                @item.State
            </td>
            <td>
                @item.ZipCode
            </td>
            <td style="white-space:nowrap;">
                <input type="button" class="ScorecardButton" id="scorecard-@item.CourseID" value="Scorecard" />
                <div id="buttonlist" style="vertical-align:middle">
                    <a href="#" title="Edit Course" class="EditButton ui-state-default ui-corner-all ui-icon ui-icon-pencil" id="edit-@item.CourseID"></a>
                    <a href="#" title="Delete Course" class="DeleteButton ui-state-default ui-corner-all ui-icon ui-icon-trash" id="delete-@item.CourseID"></a>
                </div>
            </td>
        </tr>
}
    </table>
</fieldset>
@Html.ActionLink("Back to Admin Home", "Index")